package com.bobo.base.quartz;

import org.quartz.Scheduler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

/**
 * 定时任务多线程处理通用配置
 *
 * @author LILIBO
 * @since 2021-06-24
 */
@Configuration
public class QuartzSchedulerConfig {

    @Bean
    public SchedulerFactoryBean schedulerFactoryBean() {
        SchedulerFactoryBean factory = new SchedulerFactoryBean();
        factory.setOverwriteExistingJobs(true); // 设置覆盖任务
        factory.setStartupDelay(1); // 设置延迟启动
        factory.setAutoStartup(true); // 设置自动启动
        // factory.setTaskExecutor(taskExecutor); // 设置自定义线程池
        return factory;
    }

    @Bean
    public Scheduler scheduler() {
        return schedulerFactoryBean().getScheduler();
    }

}
